//
//  serviceConfirmUpdate.m
//  upnpxdemo
//
//  Created by 赵帅 on 13-9-12.
//  Copyright (c) 2013年 wiimu.inc. All rights reserved.
//

#import "serviceConfirmUpdate.h"

@implementation serviceConfirmUpdate
#pragma mark Initialization & Deallocation

-(id)initWithDelegate:(id <serviceConfirmUpdateDelegate>) aDelegate
{
	self = [super init];
	if (self)
	{
		self.m_serviceHandler = aDelegate;
	}
    
	return self;
}



#pragma mark -
#pragma mark Configure the request
-(NSURL*)targetURL
{
    NSString * ipStr = [m_dicSendData objectForKey:@"baseurl"];
    
    NSString *urlStr = [NSString stringWithFormat:@"%@/httpapi.asp?command=getMvRemoteUpdateWriteImage",ipStr];
	NSURL *theUrl = [[NSURL alloc] initWithString:urlStr];
	
	return theUrl;
}

-(void)configureRequest
{
	[super configureRequest];
	[m_request setRequestMethod:@"GET"];
}

#pragma mark -
#pragma mark Parse the response
-(void)parseResponseData:(NSData *)data
{
	[super parseResponseData:data];
    
	NSMutableString * retStr = [NSMutableString stringWithString:m_request.responseString];
	
    if(retStr == nil)
    {
        [m_dicReceiveData setObject:SERVICE_FAIL forKey:@"responsestatus"];
        return;
    }
    
    [retStr replaceOccurrencesOfString:@"\r\n" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [retStr length])];

    
    NSLog(@"confirm state: %@",retStr);
    [m_dicReceiveData setObject:retStr forKey:@"ImageState"];
}

#pragma mark -
#pragma mark Pass Data To UI
-(void)passDataOut
{
	[super passDataOut];
	
	if (nil != self.m_serviceHandler
		&& [self.m_serviceHandler respondsToSelector:@selector(serviceConfirmUpdateCallBack:)])
	{
        [self.m_serviceHandler performSelectorOnMainThread:@selector(serviceConfirmUpdateCallBack:) withObject:m_dicReceiveData waitUntilDone:YES];
	}
}
@end
